#ifndef TIMESTAMP_H
#define TIMESTAMP_H

#include <stdint.h>

#include <boost/operators.hpp>

class TimeStamp : public boost::equality_comparable<TimeStamp>,
                  public boost::less_than_comparable<TimeStamp> {
public:
    TimeStamp();
    TimeStamp(int64_t microSecondsSinceEpoch);

    int64_t getMicroSecondsSinceEpoch() const { return microSecondsSinceEpoch_; }

    void swap(TimeStamp& rhs);

    TimeStamp addTime(TimeStamp t1, double seconds);

    static TimeStamp now();

    static TimeStamp invalid() {
        return TimeStamp();
    }

    static const int kMicroSecondsPerSecond = 1000000;

private:
    int64_t microSecondsSinceEpoch_;
};

inline bool operator<(TimeStamp lhs, TimeStamp rhs) {
    return lhs.getMicroSecondsSinceEpoch() < rhs.getMicroSecondsSinceEpoch();
}

inline bool operator==(TimeStamp lhs, TimeStamp rhs) {
    return lhs.getMicroSecondsSinceEpoch() == rhs.getMicroSecondsSinceEpoch();
}

inline TimeStamp addTime(TimeStamp ts, double seconds) {
    int64_t delta = static_cast<int64_t>(seconds * TimeStamp::kMicroSecondsPerSecond);
    return TimeStamp(ts.getMicroSecondsSinceEpoch() + delta);
}

#endif